//
//  refundReasonView.m
//  jingdongfang
//
//  Created by MTiMac02 on 2018/1/13.
//  Copyright © 2018年 LJL. All rights reserved.
//

#import "RefundReasonView.h"
#import "KLCPopup.h"
#import "RefundApplyVC.h"

@interface RefundReasonView ()
{
    UILabel *name;
    UIButton *btn1;
    UIButton *btn2;
    UIButton *btn3;
    UIButton *btn4;
    UIButton *confirmBtn;
}
@end
@implementation RefundReasonView
+ (RefundReasonView *)showRefundReasonView {
    RefundReasonView *refundView = [[RefundReasonView alloc] initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, 200)];
    refundView.backgroundColor = [UIColor whiteColor];
    refundView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    refundView.layer.borderWidth = 1.0;
    return refundView;
}

- (void)show {
    KLCPopup *pop = [KLCPopup popupWithContentView:self showType:KLCPopupShowTypeNone dismissType:KLCPopupDismissTypeSlideOutToBottom maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
    [pop show];
}
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self loadUI];
    }
    return self;
}

- (void)loadUI
{
    self.backgroundColor = [UIColor c4Color];
    name = [[UILabel alloc] init];
    name.font = [UIFont font18];
    name.textAlignment = NSTextAlignmentCenter;
    name.backgroundColor = [UIColor whiteColor];
    name.textColor = [UIColor c4Color];
    name.text = NSLocalizedString(@"Refund Reason(s)", nil);
    [name sizeToFit];
    [self addSubview:name];
    
    btn1=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn1 setTitle:NSLocalizedString(@"I Don't Like it./I Don't Want It", nil) forState:UIControlStateNormal];
    [btn1 setTitle:NSLocalizedString(@"I Don't Like it./I Don't Want It", nil) forState:UIControlStateSelected];
    [btn1 sizeToFit];
    btn1.contentEdgeInsets=UIEdgeInsetsMake(7, 10, 7, 10);
    btn1.titleLabel.textAlignment=NSTextAlignmentCenter;
    btn1.layer.cornerRadius=15;
    btn1.layer.borderWidth=1.0;
    [btn1 setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [btn1 setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [btn1 setSelected:YES];
    if (btn1.selected)
    {
        btn1.layer.borderColor=[UIColor appColor].CGColor;
    }else
    {
        btn1.layer.borderColor=[UIColor c4Color].CGColor;
    }
    btn1.titleLabel.font = [UIFont font14];
    [btn1 addTarget:self action:@selector(btn1Click:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn1];
    
    btn2=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn2 setTitle:NSLocalizedString(@"Information Filling Error/Bidding Error", nil) forState:UIControlStateNormal];
    [btn2 setTitle:NSLocalizedString(@"Information Filling Error/Bidding Error", nil) forState:UIControlStateSelected];
    [btn2 sizeToFit];
    btn2.contentEdgeInsets=UIEdgeInsetsMake(7, 10, 7, 10);
    btn2.titleLabel.textAlignment=NSTextAlignmentCenter;
    btn2.layer.cornerRadius=15;
    if (btn2.selected)
    {
        btn2.layer.borderColor=[UIColor appColor].CGColor;
    }else
    {
        btn2.layer.borderColor=[UIColor c4Color].CGColor;
    }
    btn2.layer.borderColor=[UIColor c4Color].CGColor;
    btn2.layer.borderWidth=1.f;
    [btn2 setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [btn2 setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [btn2 setSelected:NO];
    btn2.titleLabel.font = [UIFont font14];
    [btn2 addTarget:self action:@selector(btn2Click:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn2];
    
    btn3=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn3 setTitle:NSLocalizedString(@"Goods and Description Not Matched", nil) forState:UIControlStateNormal];
    [btn3 setTitle:NSLocalizedString(@"Goods and Description Not Matched", nil) forState:UIControlStateSelected];
    [btn3 sizeToFit];
    btn3.contentEdgeInsets=UIEdgeInsetsMake(7, 10, 7, 10);
    btn3.titleLabel.textAlignment=NSTextAlignmentCenter;
    btn3.layer.cornerRadius=15;
    if (btn3.selected)
    {
        btn3.layer.borderColor=[UIColor appColor].CGColor;
    }else
    {
        btn3.layer.borderColor=[UIColor c4Color].CGColor;
    }
    btn3.layer.borderColor=[UIColor c4Color].CGColor;
    btn3.layer.borderWidth=1.f;
    [btn3 setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [btn3 setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [btn3 setSelected:NO];
    btn3.titleLabel.font = [UIFont font14];
    [btn3 addTarget:self action:@selector(btn3Click:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn3];
    
    btn4=[UIButton buttonWithType:UIButtonTypeCustom];
    [btn4 setTitle:NSLocalizedString(@"Flawed/Damaged", nil) forState:UIControlStateNormal];
    [btn4 setTitle:NSLocalizedString(@"Flawed/Damaged", nil) forState:UIControlStateSelected];
    [btn4 sizeToFit];
    btn4.contentEdgeInsets=UIEdgeInsetsMake(7, 10, 7, 10);
    btn4.titleLabel.textAlignment=NSTextAlignmentCenter;
    btn4.layer.cornerRadius=15;
    if (btn4.selected)
    {
        btn4.layer.borderColor=[UIColor appColor].CGColor;
    }else
    {
        btn4.layer.borderColor=[UIColor c4Color].CGColor;
    }
    btn4.layer.borderColor=[UIColor c4Color].CGColor;
    btn4.layer.borderWidth=1.f;
    [btn4 setTitleColor:[UIColor c4Color] forState:UIControlStateNormal];
    [btn4 setTitleColor:[UIColor appColor] forState:UIControlStateSelected];
    [btn4 setSelected:NO];
    btn4.titleLabel.font = [UIFont font14];
    [btn4 addTarget:self action:@selector(btn4Click:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn4];
    
    confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmBtn addTarget:self action:@selector(confirmBtnClick) forControlEvents:UIControlEventTouchUpInside];
    confirmBtn.backgroundColor = [UIColor appColor];
//    [confirmBtn setTitle:@"确定" forState:UIControlStateNormal];
    [confirmBtn setTitle:NSLocalizedString(@"Confirm", nil) forState:UIControlStateNormal];
    confirmBtn.titleLabel.textAlignment=NSTextAlignmentCenter;
    [self addSubview:confirmBtn];
    [name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(20);
    }];
    [btn1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(name.bottom+40);
        make.left.mas_equalTo(15);
    }];
    [btn2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(name.bottom+40);
        make.left.mas_equalTo(btn1.right+15);
    }];
    [btn3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.bottom.mas_equalTo(confirmBtn.top-65);
    }];
    [btn4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(btn3.right+15);
        make.bottom.mas_equalTo(confirmBtn.top-65);
       
    }];
    [confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.bottom).mas_offset(0);
        make.width.mas_equalTo(KSCREENWIDTH);
        make.height.mas_equalTo(44);
    }];
    
}
-(void)btn1Click:(UIButton *)btn
{
    [btn setSelected:YES];
    [btn2 setSelected:NO];
    [btn3 setSelected:NO];
    [btn4 setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    btn2.layer.borderColor=[UIColor c4Color].CGColor;
    btn3.layer.borderColor=[UIColor c4Color].CGColor;
    btn4.layer.borderColor=[UIColor c4Color].CGColor;
}
-(void)btn2Click:(UIButton *)btn
{
    [btn setSelected:YES];
    [btn1 setSelected:NO];
    [btn3 setSelected:NO];
    [btn4 setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    btn1.layer.borderColor=[UIColor c4Color].CGColor;
    btn3.layer.borderColor=[UIColor c4Color].CGColor;
    btn4.layer.borderColor=[UIColor c4Color].CGColor;
}
-(void)btn3Click:(UIButton *)btn
{
    [btn setSelected:YES];
    [btn1 setSelected:NO];
    [btn2 setSelected:NO];
    [btn4 setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    btn1.layer.borderColor=[UIColor c4Color].CGColor;
    btn2.layer.borderColor=[UIColor c4Color].CGColor;
    btn4.layer.borderColor=[UIColor c4Color].CGColor;
}
-(void)btn4Click:(UIButton *)btn
{
    [btn setSelected:YES];
    [btn1 setSelected:NO];
    [btn2 setSelected:NO];
    [btn3 setSelected:NO];
    btn.layer.borderColor=[UIColor appColor].CGColor;
    btn1.layer.borderColor=[UIColor c4Color].CGColor;
    btn2.layer.borderColor=[UIColor c4Color].CGColor;
    btn3.layer.borderColor=[UIColor c4Color].CGColor;
}
- (void)confirmBtnClick
{
    if (btn1.isSelected)
    {
        self.reason=@"1";
    }
    else if (btn2.isSelected)
    {
        self.reason=@"2";
    }
    else if (btn3.isSelected)
    {
        self.reason=@"3";
    }
    else if(btn4.isSelected){
        self.reason=@"4";
    }
    __weak typeof(self) weakself = self;
    
    if (weakself.returnValueBlock) {
        //将自己的值传出去，完成传值
        weakself.returnValueBlock(self.reason);
    }
    
    [UIView prepareForInterfaceBuilder];
 
    [KLCPopup dismissAllPopups];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
